﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService.VO;

namespace WebService.DAO
{
    public class LanguageDAO
    {
        private dbConnection conn;
        /// <summary>
        /// khởi tạo đối tượng xử lý dl
        /// </summary>
        public LanguageDAO()
        {
            conn = new dbConnection();
        }
        /// <summary>
        /// kiem tra ngon ngu da co hay chua
        /// </summary>
        /// <param name="lang"></param>
        /// <returns></returns>

        public bool check(string lang)
        {
            string sqlSelect = "Select count(*) From tbl_Languages Where Language=@Lang";
            IDictionary<string, string> d = new Dictionary<string, string>();

            d.Add("@Lang", lang);

            int result = conn.ExecuteScalar(sqlSelect, d, false);
            if (result > 0)
                return true;
            return false;
        }

        /// <summary>
        /// Thêm mới 1 ngon ngu moi
        /// </summary>
        public void insert(LanguageVO lang)
        {
            string sqlInsert = "INSERT INTO tbl_Languages VALUES(@Lang,@LangName)";

            IDictionary<string, string> d = new Dictionary<string, string>();

            d.Add("@Lang", lang.Language);
            d.Add("@LangName", lang.Langname);

            conn.ExecuteQuery(sqlInsert, d, false);

        }

        /// <summary>
        /// Xóa thông tin một ngon ngu
        /// </summary>
        public void delete(string id)
        {
            string sql = "DELETE FROM tbl_Languages WHERE Language = @id";

            IDictionary<string, string> d = new Dictionary<string, string>();

            d.Add("@id", id);
            conn.ExecuteQuery(sql, d, false);
        }
        /// <summary>
        /// Cập nhật ngon ngu
        /// </summary>
        public void update(LanguageVO lang)
        {
            string sqlInsert = "UPDATE tbl_Languages SET LangName=@LangName WHERE Language=@Lang";

            IDictionary<string, string> d = new Dictionary<string, string>();
            d.Add("@Language", lang.Language);
            d.Add("@LangName", lang.Langname);

            conn.ExecuteQuery(sqlInsert, d, false);
        }
    }
}